#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2023/6/13 22:55
# @Author  : sailor233
# @File    : log.py
# @Software: PyCharm
# @Des     : 配置日志模块
import logging
import os

project_path = os.path.dirname(os.path.dirname(__file__))
# 日志路径
log_path = os.path.join(project_path, 'logs', 'log.log')

# 创建日志器logger
logger = logging.getLogger()
# 配置日志级别
logger.setLevel(logging.DEBUG)
# 创建处理器
# 文件处理器
handler = logging.FileHandler(filename=log_path, encoding='utf-8', mode='w')
# 流处理器，输出到控制台
s_handler = logging.StreamHandler()

# 创建格式器
formatter = logging.Formatter('%(asctime)s[%(levelname)s]-[%(filename)s:%(funcName)s:%(lineno)d]: %(message)s')
# 处理器 设置格式
handler.setFormatter(formatter)
s_handler.setFormatter(formatter)

# 日志器添加处理器
logger.addHandler(handler)
logger.addHandler(s_handler)
if __name__ == '__main__':
    logger.info('测试一下')
